﻿@model PagedList.IPagedList<WebSiteFool.Models.Article>
@{
    ViewBag.Title = "AllArticles";
}
<script type="text/javascript">
    $().ready(function () {
        TJBlog.AjaxLoader._loadArticleList();
        TJBlog.RichText._formatCode();
    });
</script>
<div class="b-margin-30">
@Html.ActionLink("Home", "Index", "Home", null, new { @class = "title"}) > All Articles
</div>
<div>
    @foreach (var item in Model)
    {    
        @Html.ActionLink(item.Visits.Count + " Visits" + "," + item.Comments.Count + " Comments", "Show", "Article", new { Id = item.Id }, new { @class = "comments-container" })
        
        <div>
        @Html.ActionLink(item.Title, "Show", "Article", new { Id = item.Id }, new { @class = "article-title" })
        
        <div class="article-content">@Html.Raw(item.Content)</div>
        </div>
    }
</div>
<div class="pager-container">
    @{
   
        if (Model.HasPreviousPage)
        {
        @Html.ActionLink("<Prev", "AllArticles", "Home", new { page = Model.PageNumber - 1 }, null) 
        }
        int startIndex, endIndex;
        if (Model.PageCount <= 10)
        {
            startIndex = 1;
            endIndex = Model.PageCount;
        }
        else
        {
            startIndex = Model.PageNumber - 10 > 0 ? Model.PageNumber - 8 : 1;
            endIndex = startIndex + 9 > Model.PageCount ? Model.PageCount : startIndex + 9;
        }
        if (startIndex > 1)
        {
        @Html.ActionLink("1", "AllArticles", "Home", new { page = 1 }, null) <span>...</span>
        }
        while (startIndex <= endIndex)
        {
            if (startIndex != Model.PageNumber)
            {
        @Html.ActionLink(startIndex.ToString(), "AllArticles", "Home", new { page = startIndex.ToString() }, null);
            }
            else
            {
        @Html.ActionLink(startIndex.ToString(), "AllArticles", "Home", new { page = startIndex.ToString() }, new { style = "background-color:#3b7cb4; color:#fff" });
            }

            startIndex++;
        }
        if (endIndex < Model.PageCount)
        {
        <span>...</span>
        @Html.ActionLink(Model.PageCount.ToString(), "AllArticles", "Home", new { page = Model.PageCount }, null) 
        }
        if (Model.HasNextPage)
        {
        @Html.ActionLink("Next>", "AllArticles", "Home", new { page = Model.PageNumber + 1 }, null) 
        }
    }
</div>